#!/bin/csh -f

if ( $#argv == 0 ) then
	set checkfile = "./G3S_check"
else
	set checkfile = $1
endif

if ( -e "./status" ) then
	set status = "`cat ./G3S_status`"
	switch ( "$status" )
	case "RUNNING":
		echo RUNNING
		breaksw
	case "SUCCESS":
		echo SUCCESS
		breaksw
	case "FAILED":
		echo FAILED
		breaksw
	default:
		echo UNKNOWN
		breaksw
	endsw
	exit 0
endif

# #### if no status file
# #### run the check file
if ( -x $checkfile ) then
	$checkfile
	if $? == 0 then
		echo SUCCESS
	else
		echo FAILED
	endif
	exit 0
endif

echo UNKNOWN
exit 0
